//
//  VRFirefightingRecordFoldChildCell.m
//  VRFirefighting
//
//  Created by Veer on 2018/8/18.
//  Copyright © 2018年 Veer. All rights reserved.
//

#import "VRHistoryTaskCell.h"

#import "VRHistoryTaskModel.h"

@interface VRHistoryTaskCell()

@property (nonatomic, strong) UIView *dotView;
@property (nonatomic, strong) UILabel *dateLbl;
@property (nonatomic, strong) UILabel *nameLbl;
@property (nonatomic, strong) UIView *bottomLineView;

@end

@implementation VRHistoryTaskCell

+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"VRHistoryTaskCell";
    
    VRHistoryTaskCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    
    if (nil == cell) {
        
        cell = [[VRHistoryTaskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.accessoryType = UITableViewCellAccessoryNone;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        // lieview
        [self setupSubView];
        
    }
    return self;
}


- (void)setupSubView
{

    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    
    UIView *selectedBgView = [[UIView alloc] init];
    selectedBgView.backgroundColor = RGB(238, 238, 238);
    self.selectedBackgroundView = selectedBgView;
    
    UIView *dotView = [[UIView alloc] init];
    dotView.backgroundColor = RGB(51, 51, 51);
    dotView.layer.cornerRadius = 4;
    [self.contentView addSubview:dotView];
    self.dotView = dotView;
    
    UILabel *dateLbl = [[UILabel alloc] init];
    dateLbl.textColor = RGB(80, 80, 80);;
    dateLbl.font = VRFont(16);
    [self.contentView addSubview:dateLbl];
    self.dateLbl = dateLbl;
    
    UILabel *nameLbl = [[UILabel alloc] init];
    nameLbl.numberOfLines = 0;
    nameLbl.textColor = RGB(80, 80, 80);
    nameLbl.font = VRFont(16);
    nameLbl.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:nameLbl];
    self.nameLbl = nameLbl;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = RGB(200, 200, 200);
    [self.contentView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.dotView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.centerY.mas_equalTo(self.contentView);
        make.height.width.mas_equalTo(8);
    }];
    
    [self.dateLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.dotView.mas_right).offset(10);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_greaterThanOrEqualTo(self.dateLbl.mas_right).offset(4);
    }];

    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}


#pragma mark - action


#pragma mark - setter && getter
- (void)setModel:(VRHistoryTaskModel *)model
{
    _model = model;
    
    self.dateLbl.text = [model.taskLog firstObject].fTime;
    self.nameLbl.text = [model.taskLog firstObject].fContent;
    
    CGSize nameSize = [self.dateLbl.text sizeWithFont:self.dateLbl.font];
    [self.dateLbl mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(nameSize.width + 4);
    }];
}

@end
